import 'package:flutter/material.dart';

class HistoryPage extends StatefulWidget {
  const HistoryPage({Key? key}) : super(key: key);

  @override
  State<HistoryPage> createState() => _HistoryPageState();
}

// https://cloud.tencent.com/developer/article/1763378
// AutomaticKeepAliveClientMixin仅作用于PageView、listview、GridView、IndexedStack等，所以外层
class _HistoryPageState extends State<HistoryPage> with AutomaticKeepAliveClientMixin<HistoryPage> {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(title: const Text("history")),
      body: _buildContent(),
    );
  }

  Widget _buildContent() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return Container(
          margin: const EdgeInsets.all(10),
          height: 30,
          alignment: Alignment.center,
          child: Text("index$index"),
          color: Colors.red,
        );
      },
      itemCount: 20,
    );
  }

  @override
  bool get wantKeepAlive => true;
}
